package be.nvlooy.moviereminder.entities;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.*;

@NamedQueries({
	@NamedQuery(name="Collection.getByUserAndMedia",
			query="SELECT c FROM Collection AS c " +
					"WHERE c.user = :user AND c.media = :media"),

	@NamedQuery(name="Collection.getByUser", query="SELECT c FROM Collection AS c WHERE c.user = :user"),

	@NamedQuery(name="Collection.searchByName",
			query="SELECT c FROM Collection AS c " +
					"JOIN c.media as m " +
					"WHERE c.user = :user AND LOWER(m.title) LIKE LOWER(:search)")
})

@Entity
@Table(name="mrm_collection")
public class Collection extends BaseEntity {

	@Id
	@GeneratedValue
	private long id;
	
	@ManyToOne
    @JoinColumn(name="user_id")
	private User user;
	
	@ManyToOne
    @JoinColumn(name="media_id")
	private Media media;	
	
	private Integer score;
	
	private Boolean mustSee = false;
	
	private Boolean flagPrivate = false;
	
	@OneToMany(mappedBy="collection", fetch=FetchType.EAGER)
	private List<Suggestion> suggestions = new ArrayList<Suggestion>();

	
	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public Media getMedia() {
		return media;
	}

	public void setMedia(Media media) {
		this.media = media;
	}

	public int getScore() {
		return score;
	}

	public void setScore(int score) {
		this.score = score;
	}

	public void setMustSee(boolean mustSee) {
		this.mustSee = mustSee;
	}

	public boolean isMustSee() {
		return mustSee;
	}

	public void setFlagPrivate(boolean flagPrivate) {
		this.flagPrivate = flagPrivate;
	}

	public boolean isFlagPrivate() {
		return flagPrivate;
	}

	public void setSuggestions(List<Suggestion> suggestions) {
		this.suggestions = suggestions;
	}

	public List<Suggestion> getSuggestions() {
		return suggestions;
	}
}
